package com.lin.dataobject.mapper;

import com.lin.dataobject.Product;
import com.lin.dto.ProductDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017-10-25.
 */
@Mapper
@Repository
public interface ProductMapper {
    @Insert("insert into product(id,name,remark,category) values(#{id,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR},#{category,jdbcType=INTEGER})")
    int insertByMap(Map<String,Object> map);

    @Insert("insert into product(id,name,remark,category) values(#{id,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR},#{category,jdbcType=INTEGER})")
    int insertByObject(Product product);

    @Select("select * from product where category=#{category}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "category",property = "category"),
            @Result(column = "create_time",property = "createTime"),
    })
    List<Product> findByCategory(Integer category);

    @Update("update product set name=#{name} where id=#{id}")
    int updateNameById(@Param("id") String id,@Param("name") String name);

    @Update("update product set name=#{name} where id=#{id}")
    int updateNameByObject(Product product);

    @Delete("delete from product where id=#{id}")
    int deleteById(String id);

    Product selectById(String id);

    List<ProductDTO> pageList(Map<String,Object> map);
}
